package top.ljlgithub.api.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.ljlgithub.api.bean.Report;
import top.ljlgithub.api.bean.Series;
import top.ljlgithub.api.mapper.ReportMapper;
import top.ljlgithub.api.service.ReportService;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @ClassName
 * @Description TODO
 * @Author L1470
 * @Date 2021/5/7 18:11
 * @Version 1.0
 **/
@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    ReportMapper reportMapper;

    @Override
    public Report getReport() {
        Report report = new Report();
        List<String> legend = reportMapper.getLegend();
        HashMap<String, List<String>> legendMap = new HashMap<>();
        legendMap.put("data",legend);
        report.setLegend(legendMap);
        HashMap<String, String> yMap = new HashMap<>();
        yMap.put("type","value");
        ArrayList yList = new ArrayList();
        yList.add(yMap);
        report.setYAxis(yList);
        ArrayList<Object> xList = new ArrayList<>();
        HashMap<String, List<String>> xMap = new HashMap<>();
        List<String> date = reportMapper.getDate();
        xMap.put("data",date);
        xList.add(xMap);
        report.setXAxis(xList);
        ArrayList seriesList = new ArrayList<>();
        HashMap<String, Object> areaMap = new HashMap<>();
        areaMap.put("normal",new HashMap<>());
        for (int i = 0; i < legend.size(); i++) {
            Series series = new Series();
            series.setName(legend.get(i));
            series.setAreaStyle(areaMap);
            series.setData(reportMapper.getCount(legend.get(i)));
            seriesList.add(series);
        }
        report.setSeries(seriesList);
        return report;
    }
}
